#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

/* Prototypes */
void InitUART (unsigned char baudrate);
unsigned char ReceiveByte (void);
void mydelay (void);
void TransmitByte (unsigned char data);
void forward (int steps);
void reverse (int steps);

/* --------------------------------------------------------------
 Main - simple program to spin a stepper motor.
 Forward - pass in the number of steps to spin forward  
 Revers - pass in the number of steps to spin in reverse  
---------------------------------------------------------------- */
int
main (void)
{

  DDRB = 0xFF;                  // set port B to output only
  PORTB = 0;                    // set pins low 


  forward (10);
  reverse (10);

  forward (20);
  reverse (20);

  forward (30);
  reverse (30);

  forward (40);
  reverse (40);

  forward (50);
  reverse (50);

  while (1)
    {
    }
}


void
forward (int steps)
{
  int i;
  for (i = 0; i < steps; i++)
    {
      mydelay ();               //
      PORTB = 5;
      mydelay ();               //
      PORTB = 9;
      mydelay ();               //
      PORTB = 10;
      mydelay ();               //
      PORTB = 6;
      mydelay ();               //

    }
}

void
reverse (int steps)
{
  int i;
  for (i = 0; i < steps; i++)
    {
      mydelay ();               //
      PORTB = 6;
      mydelay ();               //
      PORTB = 10;
      mydelay ();               //
      PORTB = 9;
      mydelay ();               //
      PORTB = 5;
      mydelay ();               //

    }
}

void
mydelay (void)
{
  _delay_ms (1000);            //
}

